<template>
  <div class="selected-div" ref="selected" id="mySelected">
    <div class="selected-title-div">
      <span class="selected-title">{{$t('common.hasSelected')}}</span>
      <span class="selected-clear-all"
            @click="clearAllSelected">{{$t('common.clearAll')}}</span>
    </div>
    <div class="selected-item"
         v-for="(item, index) in selectedRes"
         :key="index">
      <img style="width:30px" :src="onShowRightIcom(item)">
      <span :title="showTitle(item)"
            style="font-size: 18px;color: #393D49;margin-left: 15px;width: 165px;overflow: hidden;word-break: break-all;text-overflow: ellipsis;white-space: nowrap;">{{ showCultureResName(item)}}</span>
      <span style="cursor: pointer;" @click="omRemoveRes(item)">X</span>
    </div>
  </div>
</template>

<script>
  import util from '../../common/util'

  export default {
    name: "SelectedResList",
    props: {
      homeType: {
        default: 1
      }
    },
    data() {
      return {
        language: ''
      }
    },
    computed: {
      selectedRes() {
        console.log(this.$store.state)
        return this.$store.state.resources.selected
      }
    },
    created() {
      this.language = this.$route.query.culture
    },
    methods: {
      showTitle(item) {
        console.log(item.resourceName)
          return item.resourceName
      },
      /**
       * 根据环境显示资源名称
       */
      showCultureResName(item) {
          return item.resourceName
      },
      omRemoveRes(item) {
        this.$store.commit('resources/incrementSelectedRes', item)
      },
      onShowRightIcom(item) {
        return item.resourceIcon
      },
      clearAllSelected() {
        this.$store.commit('resources/clearAllSelectedRes')
      }
    }
  }
</script>

<style scoped>
  .selected-div {
    width: 278px;
    background: #FFFFFF;
    border: 1px solid #CCCCCC;
    overflow: auto;
  }

  .selected-div::-webkit-scrollbar {
    width: 2px;
  }

  .selected-title {
    font-size: 24px;
    color: #393D49;
    font-weight: bold;
    margin-left: 21px;
    width: 100px;
  }

  .selected-title-div {
    display: flex;
    align-items: center;
    margin-top: 30px;
    margin-bottom: 20px
  }

  .selected-clear-all {
    width: 80px;
    height: 30px;
    background: #EDEDED;
    border-radius: 4px;
    text-align: center;
    line-height: 29px;
    font-size: 16px;
    color: #393D49;
    margin-left: 59px;
    cursor: pointer;
  }

  .selected-item {
    height: 48px;
    border-bottom: 1px solid #cccccc;
    display: flex;
    align-items: center;
    width: 218px;
    margin: 0 auto;
  }
</style>
